<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/zhuce.css">
    <script src="../js/jquery-3.5.1.js"></script>
    <script src="../js/utils.js"></script>
</head>

<body>
    <form method="submit">
        <div class="title" ng-class="loginLogoClass">
            <div class="cloud"><img src="../img/cloud_b308865e15@2x.png" alt=""></div>
            <h4>使用 Smartisan ID 登录官网</h4>
        </div>
        <div class="content">
            <p class="err">两次密码不一致</p>
            <p class="username"><span>账 号 ： </span><input type="text"></p>
            <p class="password"><span>密 码 ： </span><input type="password"></p>
            <p class="rpassword"><span>重 复 ： </span><input type="password"></p>
            <p class="nickname"><span>昵 称 ： </span><input type="text"></p>
            <button id="zhuce">确认注册</button>
        </div>
    </form>

    <div>
        <h3>Copyright © 2020 smartisan.com 版权所有</h3>
        <a href="https://beian.miit.gov.cn/#/Integrated/index">京 ICP 备 18020659 号 - 2</a>
    </div>
    <script>
        $('#zhuce').on('click', function (e) {
            e.preventDefault()
            // console.log($('.password > input')[0].value,$('.rpassword')[0].value);
            if ($('.password > input')[0].value != $('.rpassword > input')[0].value) return $('.err').addClass('active')
            ajax({
                url: 'http://10.9.46.151:8080/usertest',
                method: 'GET',
                success(res) {
                    res = JSON.parse(res)
                    for (let i = 0; i < res.length; i++) {
                        if (res[i].username == $('.username > input')[0].value) {
                            return $('.err').text('用户名已存在').addClass('active')
                        }
                    }
                    const data = JSON.stringify({ username: $('.username > input')[0].value, password: $('.password > input')[0].value, nickname: $('.nickname > input')[0].value })
                    ajax({
                        url: 'http://10.9.46.151:8080/adduser',
                        data: data,
                        dataType: 'json',
                        method: 'POST',
                        success(res) {

                        }
                    })
                    window.alert('注册成功')
                    location.href = './login.html'
                }
            })
        })
    </script>
</body>

</html>